package org.luckyjourney.entity.vo;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.ToString;

import java.io.Serializable;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.util.Objects;

/**
 * @description:
 * @Author: friday
 * @CreateTime: 2023-10-31 01:12
 */
@Data
@NoArgsConstructor
@ToString
public class HotVideo implements  Serializable {

    private static final long serialVersionUID = 1L;

    String hotFormat;

    Double hot;

    Long videoId;

    String title;

    public HotVideo(Double hot,Long videoId,String title){
        this.hot = hot;
        this.videoId = videoId;
        this.title = title;
    }

    // TODO: 项目素材较少，暂时不使用
    // public void hotFormat(){
    //     BigDecimal bigDecimal = new BigDecimal(this.hot);
    //     BigDecimal decimal = bigDecimal.divide(new BigDecimal("10000"));
    //     DecimalFormat formater = new DecimalFormat("0.0");
    //     formater.setRoundingMode(RoundingMode.HALF_UP);    // 5000008.89
    //     String formatNum = formater.format(decimal);
    //     this.setHotFormat( formatNum+"万");
    // }

    // 移除了除以10000的操作，移除了"万"字的添加直接使用DecimalFormat格式化热度值，
    // 保留一位小数现在热度排行榜将直接显示0-10之间的热度值，例如：
    // 5.8
    // 3.2
    // 1.5
    public void hotFormat(){
        DecimalFormat formater = new DecimalFormat("0.0");
        formater.setRoundingMode(RoundingMode.HALF_UP);
        this.setHotFormat(formater.format(this.hot));
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;
        HotVideo hotVideo = (HotVideo) o;
        return Objects.equals(videoId, hotVideo.videoId) &&
                Objects.equals(title, hotVideo.title);
    }

    @Override
    public int hashCode() {
        return Objects.hash(videoId, title);
    }
}
